#! /bin/sh
# Start script used to start Akka runtime on a unix workstation.
# Uses the current working directory instead of hardcoded paths like the production script
# In addition some parameters like default memory sizes and such are decreased to fit a workstation better 

OTHELLO_HOME=CHANGE_TO_PROJ_DIR/dist
export AKKA_HOME=$OTHELLO_HOME

if [  "${AKKA_HOME:+1}" != "1" ]; then
        echo Enviroment variable AKKA_HOME is undefined
        exit 1
fi;

if [  "${OTHELLO_HOME:+1}" != "1" ]; then
        echo Enviroment variable OTHELLO_HOME is undefined
        exit 1
fi;

OTHELLO_CLASSPATH=:$OTHELLO_HOME/.;$OTHELLO_HOME/config/.

cd $AKKA_HOME
for jarfile in ./deploy/*.jar ; do
    OTHELLO_CLASSPATH=$OTHELLO_CLASSPATH:$jarfile
done

for jarfile in ./lib/*.jar ; do
    OTHELLO_CLASSPATH=$OTHELLO_CLASSPATH:$jarfile
done

JAVA_OPTS="$JAVA_OPTS -Dlog.path=."

# Remote JMX monitoring
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=60000 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

# Memory parameters
# Optimized for better performance
#JAVA_OPTS="$JAVA_OPTS -server -Xms256m -Xmx1024m -XX:NewSize=256m"
# Default for lower memory footprint
JAVA_OPTS="$JAVA_OPTS -server -Xms256m -Xmx512m"

# Garbage collector settings
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:gc-othello.log"

echo "OTHELLO_CLASSPATH -> $OTHELLO_CLASSPATH"
echo "AKKA_HOME -> $AKKA_HOME"
echo "JAVA_OPTS -> $JAVA_OPTS"
java $JAVA_OPTS -cp $OTHELLO_CLASSPATH com.segersten.othello.service.Boot $@ & echo $! > $AKKA_HOME/akka-runtime.pid

